using System;
using System.Collections.Generic;
using static SmartSite.Common.CheckingNullArgument;

namespace SmartSite.Frame
{
    public abstract class Field<T> : IField
    {
        protected BitsVariable BitsVariable { get; }
        public List<byte> Buffer { get => BitsVariable.Buffer; }
        public BitUnit Index { get => BitsVariable.Index; }
        public BitUnit Count { get => BitsVariable.Count; }
        public BitUnit EndIndex { get { return Index + Count; } }

        public abstract T Value { get; set; }

        public Field(List<byte> buffer, BitUnit index, BitUnit count)
        {
            BitsVariable = new BitsVariable(buffer, index, count);
        }

        public Field(IBytesBuffer buffer, BitUnit index, BitUnit count)
            : this(CheckingNull(buffer, nameof(buffer)).Buffer, index, count) { }

        public Field(IField field, BitUnit count)
            : this(CheckingNull(field, nameof(field)).Buffer, field.EndIndex, count) { }

    }
}
